package com.matrix.index.ui.anime.adapter

import android.graphics.Bitmap
import android.graphics.BitmapFactory
import android.widget.ImageView
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.viewholder.BaseViewHolder
import com.matrix.index.R
import com.matrix.index.ui.anime.bean.Root
import com.matrix.index.views.hive.HiveDrawable
import com.matrix.index.views.hive.HiveLayoutManager

class AnimAdapter(layoutResId: Int, data: ArrayList<Root>) :
    BaseQuickAdapter<Root, BaseViewHolder>(layoutResId, data) {
    private var images: ArrayList<Int> = arrayListOf()

    init {
        images.add(R.drawable.icon_anim_erciyuan)
        images.add(R.drawable.icon_anim_sanciyuan)
        images.add(R.drawable.icon_anim_xuni)
        images.add(R.drawable.icon_anim_juese)
        images.add(R.drawable.icon_anim_youxi)
        images.add(R.drawable.icon_anim_dongmanxl)
        images.add(R.drawable.icon_anim_bqb)
    }

    override fun convert(holder: BaseViewHolder, item: Root) {
        holder.setText(R.id.tv_name, item.label)
        val drawable =
            HiveDrawable(
                HiveLayoutManager.VERTICAL,
                getBitmap(images[holder.layoutPosition % images.size])
            )
        holder.getView<ImageView>(R.id.iv_cover).setImageDrawable(drawable)
    }

    private fun getBitmap(resId: Int): Bitmap {
        var bitmap: Bitmap = BitmapFactory.decodeResource(context.resources, resId)
        return bitmap
    }
}